package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.GoodsDao;
import com.atguigu.jxc.dao.SupplierDao;
import com.atguigu.jxc.entity.Goods;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.GoodsService;
import com.atguigu.jxc.service.SupplierService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.gson.JsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * ClassName: SupplierServiceImpl
 * Description:
 * Date: 2022/1/15 16:03
 *
 * @version:
 * @since JDK 1.8
 */
@Service
public class SupplierServiceImpl implements SupplierService {

    @Autowired
    private SupplierDao supplierDao;

    @Override
    public Page<Supplier> selectPage(Integer page, Integer rows, String supplierName) {


        PageHelper.startPage(page,rows);
        Page<Supplier> supplierPage =  supplierDao.findPage(supplierName);

        return supplierPage;
    }


    @Override
    public void deleteSupplierByIds(String ids) {

        String[] arr = ids.split(",");
        for (String s : arr) {
            deleteSupplierById(new Integer(s));
        }


    }

    private void deleteSupplierById(Integer supplierId) {
        supplierDao.deleteSupplierById(supplierId);

    }

    @Override
    public void insertOrUpdateSupplier(Supplier supplier) {

        if(supplier.getSupplierId() != null){
            supplierDao.UpdateSupplierById(supplier);
        }else{
            supplierDao.insertSupplier(supplier);
        }

    }


    @Override
    public List<Supplier> getComboboxList(String q) {

        List<Supplier> supplierList = supplierDao.getComboboxList(q);
        return supplierList;
    }
}


